﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WOS.Common
{
    public enum SpeedFormat
    {
        KilobytesPerSecond
    }
    public sealed class Speed
    {
        #region Constants
        public static readonly Speed Zero = new Speed(0);
        public static readonly Speed Empty = new Speed();
        #endregion
        #region Private Fields
        private readonly long? bytes;
        #endregion
        #region Constructros
        private Speed()
        {
        }

        public Speed(long bytes)
        {
            this.bytes = bytes;
        }
        #endregion

        #region Public Members
        public string ToString(SpeedFormat format)
        {
            if (!this.bytes.HasValue)
                return String.Empty;

            var speed = this.bytes.Value / 1024.0;

            switch (format)
            {
                case SpeedFormat.KilobytesPerSecond: return String.Format("{0} kB/s", speed.ToString("0.00"));
                default: throw new NotSupportedException();
            }
        }
        #endregion
        #region Overridden Members
        public override string ToString()
        {
            return this.ToString(SpeedFormat.KilobytesPerSecond);
        }
        #endregion
    }
}
